/*LICENSE_BEGIN
 * ******************************************************************
 * Copyright 2006 by the Dainamite Robocup-Team at the
 * DAI-Labor, TU-Berlin (www.dai-labor.de)
 * 
 * Members of Dainamite are:
 * Holger Endert
 * Robert Wetzker
 * Thomas Karbe
 * Axel Heßler
 * Philippe Bütter
 * Felix Brossmann
 * 
 * Licensed under the GNU GPL (General Public License) Free Software 
 * License, Version 2. You may use this file only in compliance with 
 * the License. You may obtain a copy of the License at:
 * 
 * http://www.fsf.org/licensing/licenses/gpl.txt
 * ******************************************************************
LICENSE_END*/
package robocup.component.worldobjects;

import robocup.component.geometry.Vektor;

/**
 * StaticObject is the representation of anything on the soccerfield,
 * that has a position. It therefore is extended by the classes Flag
 * and DynamicObject.
 */
public abstract class StaticObject {

	/**
	 * The cycle, in which it was seen.
	 */
	private int cycle = -1;

	/**
	 * The bodyCycle, in which it was seen (this is incremented always,
	 * not only if a new gameCycle arrives)
	 */
	private int bodyCycle = -1;

	/**
	 * The position of the StaticObject.
	 */
	protected Vektor position = new Vektor();

	/**
	 * Creates a new <code>StaticObject</code>, an object that has a
	 * position, but not a speed.
	 * 
	 * @param iCycle -
	 *            time, when the object was seen last (real cycle)
	 * @param bodyCycle -
	 *            time, when the object was seen last (body cycle)
	 * @param iPosAbs -
	 *            the absolute position of the object
	 */
	public StaticObject(int iCycle, int bodyCycle, Vektor iPosAbs) {
		this.cycle = iCycle;
		this.position.x = iPosAbs.x;
		this.position.y = iPosAbs.y;
		this.bodyCycle = bodyCycle;
	}

	/**
	 * @return Returns the cycle.
	 */
	public int getCycle() {
		return this.cycle;
	}

	/**
	 * <code>getPosition</code>
	 * 
	 * @return Returns the object's position. Note that if you perform
	 *         operations on this Vektor that change it, you need to clone it
	 *         first!
	 */
	public final Vektor getPosition() {
		if (this.position == null)
			this.position = new Vektor();
		return this.position;
	}

	/**
	 * distance to an object
	 * 
	 * @param o -
	 *            StaticObject
	 * @return distance to the object
	 */
	public final double getDistance(StaticObject o) {
		return this.getPosition().getDistance(o.getPosition());
	}

	/**
	 * distance to a point (Vektor)
	 * 
	 * @param v -
	 *            point
	 * @return distance to the object
	 */
	public final double getDistance(Vektor v) {
		return this.getPosition().getDistance(v);
	}

	/**
	 * @param o -
	 *            StaticObject with global position
	 * @return Vektor - from the position of this StaticObject to the position
	 *         of the specified StaticObject <code>o</code>.
	 */
	public final Vektor getVektorTo(StaticObject o) {
		return getVektorTo(o.getPosition());
	}

	/**
	 * @param absolutePosition -
	 *            global Vektor
	 * @return Vektor - from this Vektor to the specified global Vektor
	 *         <code>absolutePosition</code>
	 */
	public final Vektor getVektorTo(Vektor absolutePosition) {
		return getPosition().getVektorTo(absolutePosition);
	}

	/**
	 * @param o -
	 *            StaticObject with global position
	 * @return double - angle from the position of this StaticObject to the
	 *         global position of the specified StaticObject <code>o</code>
	 */
	public final double getAngleTo(StaticObject o) {
		return getAngleTo(o.getPosition());
	}

	/**
	 * @param absolutePosition -
	 *            global Vektor
	 * @return double - angle from the position of this StaticObject to the
	 *         global Vektor <code>absolutePosition</code>.
	 */
	public final double getAngleTo(Vektor absolutePosition) {
		return getPosition().getAngleTo(absolutePosition);
	}

	/**
	 * @param cycle
	 *            The cycle to set.
	 */
	public void setCycle(int cycle) {
		this.cycle = cycle;
	}

	/**
	 * @param position
	 *            The position to set.
	 */
	public void setPosition(Vektor position) {
		this.position.x = position.x;
		this.position.y = position.y;
	}

	/**
	 * @return Returns the bodyCycle.
	 */
	public int getBodyCycle() {
		return this.bodyCycle;
	}

	/**
	 * @param bodyCycle
	 *            The bodyCycle to set.
	 */
	public void setBodyCycle(int bodyCycle) {
		this.bodyCycle = bodyCycle;
	}
}
